import requests

# 添加员工
resp = requests.post(url="https://heimahr.itheima.net/api/sys/user",
                     headers={"Content-Type": "application/json",
                              "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTczNDc3MjQxNiwiZXhwIjoxNzM0Nzk0MDE2fQ.6ej5B6xFzrg4VipUzLWRJGb2KR79U_V5jXmC91E1BDw"},
                     json={
                         "username": "齐天五圣",
                         "mobile": "13349686895",
                         "workNumber": "",
                         "formOfEmployment": 1,
                         "departmentId": 2,
                         "timeOfEntry": "2024-12-05",
                         "correctionTime": "2024-12-11T16:00:00.000Z",
                         "staffPhoto": ""
                     })
print(resp.json())
a = int(resp.json().get("data").get("id"))



# 查询员工
resp_query = requests.get(url=f"https://heimahr.itheima.net/api/sys/user/{a}",
                          headers={"Content-Type": "application/json",
                                   "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTczNDc3MjQxNiwiZXhwIjoxNzM0Nzk0MDE2fQ.6ej5B6xFzrg4VipUzLWRJGb2KR79U_V5jXmC91E1BDw"},
                          )
print(resp_query.json())

# 修改员工
resp_modify = requests.put(url=f"https://heimahr.itheima.net/api/sys/user/{a}",
                    headers={"Content-Type": "application/json",
                             "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTczNDc3MjQxNiwiZXhwIjoxNzM0Nzk0MDE2fQ.6ej5B6xFzrg4VipUzLWRJGb2KR79U_V5jXmC91E1BDw"},
                    json={
                            "id": a,
                            "mobile": "13349686895",
                            "staffPhoto": "",
                            "username": "齐天八圣",
                            "workNumber": "HEIMA00036",
                            "timeOfEntry": "2024-12-05",
                            "correctionTime": "2024-12-12",
                            "departmentId": 3,
                            "departmentName": "总裁办",
                            "formOfEmployment": 1,
                            "roleIds": []
                        })
print(resp_modify.json())
# # 删除员工
resp_del = requests.delete(url=f"https://heimahr.itheima.net/api/sys/user/{a}",
                    headers={"Content-Type": "application/json",
                             "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTczNDc3MjQxNiwiZXhwIjoxNzM0Nzk0MDE2fQ.6ej5B6xFzrg4VipUzLWRJGb2KR79U_V5jXmC91E1BDw"},
                    )
print(resp_del.json())
